<template>
  <div>
    <div class="title">
      <h1>{{picinfo.title}}</h1>
      <p class="subtitle">
        <span>发表时间{{picinfo.add_time | dataFormat}}</span>
        <span>点击：{{picinfo.click}}</span>
      </p>
    </div>
    <hr />
    <div class="piccontent">
      <div class="thumbs">
        <vue-preview :slides="slide1" @close="handleClose" class="prev"></vue-preview>
      </div>

      <div v-html="picinfo.content"></div>
    </div>
    <cmt-pl :id="id"></cmt-pl>
  </div>
</template>

<script>
import comments from "../news/comments.vue";
import { Toast } from "mint-ui";
export default {
  data() {
    return {
      id: this.$route.params.id,
      picinfo: {},
      slide1: []
    };
  },
  created() {
    this.getpicinfo();
    this.getThumbs();
  },
  methods: {
    getpicinfo() {
      this.$http
        .get("http://www.liulongbin.top:3005/api/getimageInfo/" + this.id)
        .then(result => {
          if (result.body.status === 0) {
            this.picinfo = result.body.message[0];
          } else {
            Toast("图片详情加载失败");
          }
        });
    },
    getThumbs() {
      this.$http
        .get("http://www.liulongbin.top:3005/api/getthumimages/" + this.id)
        .then(result => {
          if (result.body.status === 0) {
            result.body.message.forEach((item, i) => {
              i++;
              item.w = 600;
              item.h = 400;
              item.msrc = item.src;
              item.alt = "picture" + i;
              item.title = "Image Caption " + i;
            });
            this.slide1 = result.body.message;
          } else {
            Toast("缩略图加载失败");
          }
        });
    },
    handleClose() {
      console.log("close event");
    }
  },
  components: { "cmt-pl": comments }
};
</script>

<style lang="scss" >
.title {
  text-align: center;
  h1 {
    font-size: 15px;
    color: blue;
  }
  .subtitle {
    font-size: 13px;
    display: flex;
    justify-content: space-between;
    color: blue;
  }
}
.piccontent {
  font-size: 13px;

  .thumbs {
    .my-gallery {
      display: flex;
      flex-wrap: wrap;
      figure {
        width: 30%;
        margin: 5px;
        img {
          width: 100%;
        }
      }
    }
  }
}
</style>
